import { Component, OnInit, ViewEncapsulation, ViewChild } from '@angular/core';
import { ToastComponent } from 'ngx-weui';
import { HttpService } from '../../service/http.service';

@Component({
  selector: 'app-addpatient',
  templateUrl: './addpatient.component.html',
  styleUrls: ['./addpatient.component.css'],
  encapsulation: ViewEncapsulation.None
})

export class AddpatientComponent implements OnInit {
  @ViewChild('success') successToast: ToastComponent;
  @ViewChild('loading') loadingToast: ToastComponent;
  //新增就诊人接口
  addpatienturl = 'patient!bindWithWX';
  //新增就诊人必须的字段
  name: string;
  idcard: string;
  mobile: string
  cardId: string;

  constructor(private httpservice: HttpService) { }

  onshow(type: 'success' | 'loading') {
    (<ToastComponent>this[`${type}Toast`]).onShow();
  }

  hide() {
    console.log(1)
  }

  onSubmit() {
  }

  ngOnInit() {
  }

  addPatient() {
    (<ToastComponent>this[`${'loading'}Toast`]).onShow();
    let sex = this.httpservice.sex(this.idcard);
    let data = "{p_id_card:'" + this.idcard + "',p_name:'" + this.name + "',p_sex:'" + sex + "',p_tel:'" + this.mobile + "',p_brid:'64',wx_openid:'123'}";
    this.httpservice.httpPost(this.addpatienturl, data).subscribe(res => {
      if (this.httpservice.dataFilter(res)) {
        (<ToastComponent>this[`${'loading'}Toast`]).onHide();
        (<ToastComponent>this[`${'success'}Toast`]).onShow();
        console.log(res.data);
        setTimeout(() => {
          history.go(-1);
        }, 1000)
        //history.go(-1);
        ///this.schedulinglist = res.data.data;
        //sessionStorage.setItem('schedulingdate',JSON.stringify(this.schedulingdate[i][j]));
        //console.log('接口名称:' + this.schedulingurl, this.schedulinglist);
      }
    });
  }

}